package com.glasses.business.fragment;

import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.glasses.business.R;
import com.glasses.business.appliction.MyApplication;
import com.glasses.business.base.AppBaseFragment;
import com.glasses.business.http.NetUtils;
import com.glasses.business.utils.Tools;

import net.neiquan.applibrary.wight.AlertDialog;
import net.neiquan.okhttp.NetCallBack;
import net.neiquan.okhttp.ResultModel;

import org.haitao.common.utils.RegexValidateUtil;
import org.haitao.common.utils.ToastUtil;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Author：邓勇军
 * English Name：Deng,The Sky Fucker!
 * Email：dandycoder@126.com
 * Date：2017/3/8
 * Version：1.0
 */

public class SuggestFragment extends AppBaseFragment {
    @InjectView(R.id.suggestContent)
    EditText suggestContent;
    @InjectView(R.id.suggestPhone)
    EditText suggestPhone;
    @InjectView(R.id.suggestSubmit)
    TextView suggestSubmit;

    @Override
    public int getRootViewId() {
        return R.layout.fragment_suggest;
    }

    @Override
    public void setViews() {
        setTitleTv("意见反馈");
    }

    @Override
    public void initData() {

    }

    @Override
    public boolean mainTabShow() {
        return false;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.inject(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    @OnClick(R.id.suggestSubmit)
    public void onClick() {
        String content = suggestContent.getText().toString();
        String phone = suggestPhone.getText().toString();
        if(TextUtils.isEmpty(content)){
            ToastUtil.shortShowToast("请先输入反馈内容...");
        }else if(!RegexValidateUtil.checkCellphone(phone)){
            ToastUtil.shortShowToast("请先输入正确的手机号码...");
        }else{
            Tools.showDialog(getActivity());
            NetUtils.getInstance().feedBack(content, phone, new NetCallBack() {
                @Override
                public void onSuccess(String response, String mssage, ResultModel model) {
                    Tools.dismissWaitDialog();
//                    ToastUtil.shortShowToast(mssage);
                    new AlertDialog.Builder(getActivity()).setTitle("提交成功")
                            .setMessage("感谢您的高贵意见或建议,我们将不断改进，为您提供更好的服务！")
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                                    MyApplication.getInstance().manager.onBackPressed();
                                }
                            }).create().show();
                }

                @Override
                public void onFail(boolean dataError, int errorCode, String mssage) {
                    Tools.dismissWaitDialog();
                    ToastUtil.shortShowToast(mssage);
                }
            },null);
        }

    }
}
